from django.shortcuts import render
# render 函数用来将数据渲染到指定的模板中 并返回html内容
from django.shortcuts import render
# http响应的结构
from django.http import JsonResponse, HttpResponse
from .utils import getPublicData
from .utils import getCenterData
from .utils import getCenterLeftData


# Create your views here.

def center(request):
    if request.method == 'GET':
        sumCar, highVolume, topCar, mostModel, mostBrand, averagePrice = getCenterData.getBaseData()
        lastSortList = getCenterData.getRowData()
        oilRate, tramRate, otherRate = getCenterData.getTypeRate()
        return JsonResponse({
            'sumCar': sumCar,
            'highVolume': highVolume,
            'topCar': topCar,
            'mostModel': mostModel,
            'mostBrand': mostBrand,
            'averagePrice': averagePrice,
            'lastSortList': lastSortList,
            'oilRate': oilRate,
            'tramRate': tramRate,
            'otherRate': otherRate
        })


def centerLeft(request):
    if request.method == 'GET':
        lastPieList = getCenterLeftData.getPieBrandData()
        return JsonResponse({
            'lastPieList': lastPieList
        })
